<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use kartik\select2\Select2;
use yii\helpers\ArrayHelper;
use yii\widgets\Pjax;
use yii\grid\GridView;

/* @var $this yii\web\View */
/* @var $searchModel app\models\GkyQyhDepartmentSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = 'Gky Qyh Departments';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="gky-qyh-department-index">

    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <div class="col-lg-12">
        <?php
        $form = ActiveForm::begin([
                    'action' => ['index'],
                    'method' => 'get',
                    'options' => ['class' => 'input-group col-md-12'],
                    'fieldConfig' => [
                        'template' => '<div class="col-lg-12 col-md-12">{input}</div>',
                    ]
                ])
        ?>

        <div class="col-lg-4 col-md-4">
            <label style="float: left;margin-top: 5px;">部门名称</label>
            <div style="overflow: hidden;">
                <?php
                $datas = app\models\GkyQyhDepartment::find()->all();
                if ($datas != null) {
                    foreach ($datas as $item) {
                        $source[] = $item->name;
                    }
                } else {
                    $source[] = array();
                }
                echo yii\jui\AutoComplete::widget([
                    'model' => $searchModel,
                    'attribute' => 'name',
                    'options' => ['style' => 'margin-left:10px'],
                    'clientOptions' => [
                        'source' => $source,
                    ],
                ]);
                ?>       
            </div>



        </div>
        <div class="col-lg-6 col-md-6">
            <?= Html::submitButton('查找', ['class' => 'btn btn-primary']) ?>
            <?= Html::a('创建', ['create'], ['class' => 'btn btn-primary']) ?>
            <?= Html::a('同步', ['index', 'isUpdata' => true], ['class' => 'btn btn-primary']) ?>

        </div>

        <div class="row" style="margin: 10px 0 15px 15px;">

        </div>

        <?php ActiveForm::end(); ?>    
        <?php Pjax::begin(); ?>
        <?=
        GridView::widget([
            'dataProvider' => $dataProvider,
            'columns' => [
                //  ['class' => 'yii\grid\SerialColumn'],
//            'id',
//            'dno',
//            'name',
                [
                    'attribute' => 'name',
                    'label' => '部门名称',
                    'format' => 'raw',
                    'value' => function ($model) {
                        return Html::a($model->name, ['gky-qyh-department/view', 'id' => $model->id]);
                    }
                        ],
//            'parentid',
                        [
                            'attribute' => 'parentid',
                            'label' => '父级部门',
                            'value' => function ($model) {
                                if ($model->parent) {
                                    return $model->parent->name;
                                } else {
                                    return "";
                                }
                            }
                        ],
//            'order',
                        // 'qyh_id',
                        [
                            'class' => 'yii\grid\ActionColumn',
                            'template' => '{update} {delete}',
                            'buttons' => [
                                //view button
//                    'view' => function ($url) {
//                        return Html::a('<span class="fa fa-search"></span>查看', $url, [
//                                    'title' => Yii::t('app', 'View'),
//                                        //  'class' => 'btn btn-primary btn-xs',
//                        ]);
//                    },
                                //update button
                                'update' => function ($url) {
                                    return Html::a('<span class="fa fa-search"></span>编辑', $url, [
                                                'title' => Yii::t('app', 'Update'),
                                                    // 'class' => 'btn btn-primary btn-xs',
                                    ]);
                                },
                                        //update button
                                        'delete' => function ($url) {
                                    return Html::a('<span class="fa fa-search"></span>删除', $url, [
                                                'title' => Yii::t('app', 'Delete'),
                                                'data-confirm' => Yii::t('yii', 'Are you sure you want to delete this item?'),
                                                'data-method' => 'post',
                                                'data-pjax' => '0',
                                                    //  'class' => 'btn btn-primary btn-xs',
                                    ]);
                                },
                                    ],
                                ],
                            ],
                        ]);
                        ?>
                        <?php Pjax::end(); ?>
    </div>
</div>
